<?php

function fnInsertPaper($UserId,$SeminarId,$Title,$Summary) {
    $results = mysql_query("INSERT INTO `mst_paper` (user_id,seminar_id,title,summary)
                            VALUES ('$UserId','$SeminarId','$Title','$Summary') ");
    return $results;
}
    
function fnUpdatePaper($UserId,$SeminarId,$Title,$Summary,$Remark,$PaperId) {
    $results = mysql_query("UPDATE `mst_paper` 
                            SET user_id='$UserId',
                                seminar_id='$SeminarId',
                                title='$Title',
                                summary='$Summary',
                                remark='$Remark' 
                            WHERE paper_id='$PaperId'");
    return $results;
}
    
function fnDeletePaper($PaperId) {
    $results = mysql_query("DELETE FROM `mst_paper` 
                            WHERE `paper_id` = '$PaperId'");
    return $results;
}

function fnGetPaperId($UserId,$SeminarId,$Title) {
    $results = mysql_query("SELECT paper_id FROM `mst_paper` 
                            WHERE user_id='$UserId' 
                            AND seminar_id='$SeminarId' 
                            AND trim(title)=trim('$Title')");
    return $results;
}

function fnGetAllPaper($UserId,$SeminarId) {
    $results = mysql_query("SELECT * FROM `v_detil_paper` 
                            WHERE user_id='$UserId' 
                            AND seminar_id='$SeminarId'");
    return $results;
}

function fnGetAllSpeaker($topikId) {
    $results = mysql_query("SELECT distinct user_id, nama 
                            FROM `v_pembicara_file_seminar` 
                            WHERE seminar_id = '$topikId'");
    return $results;
}

function fnSelectSpeaker($speakerId) {
    $results = mysql_query("SELECT * FROM `v_pembicara_file_seminar` 
                            WHERE user_id = '$speakerId'");
    return $results;
}

function fnGetFileInfo($speakerId) {
    $results = mysql_query("SELECT * FROM `v_pembicara_file_seminar` 
                            WHERE user_id = '$speakerId'");
    return $results;
}

function fnGetListFile() {
    $results = mysql_query("SELECT * FROM `v_pembicara_file_seminar` order by upload_date");
    return $results;
}

function fnSaveRemark($PaperId, $UserId, $SeminarId, $Komen) {
    $results = mysql_query("UPDATE mst_paper SET remark = '$Komen' 
                            WHERE paper_id = $PaperId 
                            AND user_id = $UserId
                            AND seminar_id = $SeminarId");
    return $results;
}   

function fnSaveScore($paperId, $reviewerId, $score) {
    $results = mysql_query("INSERT INTO mst_score (paper_id, reviewer_id, review_date, score) 
                            VALUES ($paperId, $reviewerId, curdate(), $score) ");
    return $results;
}

function fnGetPaperScore($paperId, $userId, $seminarId, $reviewerId) {
    $results = mysql_query("select a.remark, b.score from mst_paper a 
                            left outer join mst_score b 
                            on a.paper_id = b.paper_id
                            where 1=1 
                            and a.paper_id = $paperId
                            and a.user_id = $userId
                            and a.seminar_id = $seminarId ");
    return $results;
}

function fnGetTopList() {
    $results = mysql_query("SELECT nama, tema, title, summary, remark, reviewer, review_date, score
                            , upload_date, user_telp, reviewer_telp 
                            FROM `v_paper_score_seminar_user_rev`");
    return $results;
}

function fnGetTopListById($SeminarId) {
    $results = mysql_query("SELECT nama, tema, title, summary, remark, reviewer, review_date, score
                            , upload_date, user_telp, reviewer_telp 
                            FROM `v_paper_score_seminar_user_rev` 
                            WHERE seminar_id = ".$SeminarId);
    return $results;
}

function fnPaperReviewer($PaperId) {
    $results = mysql_query("SELECT paper_id, nama, telp, email  
                            FROM `v_paper_score_reviewer`
                            WHERE paper_id = ".$PaperId);
    return $results;
}
?>
